<template>
  <lbr-form class="form" ref="form" :model="user" :rules="rules">
    <lbr-form-item label="用户名" prop="username">
      <!-- <lbr-input v-model="user.username"></lbr-input> -->
      <lbr-input
        :value="user.username"
        @input="user.username = $event"
        placeholder="请输入用户名"
      ></lbr-input>
    </lbr-form-item>
    <lbr-form-item label="密码" prop="password">
      <lbr-input type="password" v-model="user.password"></lbr-input>
    </lbr-form-item>
    <lbr-form-item>
      <lbr-button type="primary" @click="login">登 录</lbr-button>
    </lbr-form-item>
  </lbr-form>
</template>

<script>
import LbrForm from './form/Form';
import LbrFormItem from './form/FormItem';
import LbrInput from './form/Input';
import LbrButton from './form/Button';
export default {
  components: {
    LbrForm,
    LbrFormItem,
    LbrInput,
    LbrButton,
  },
  data() {
    return {
      user: {
        username: '',
        password: '',
      },
      rules: {
        username: [
          {
            required: true,
            message: '请输入用户名',
          },
        ],
        password: [
          {
            required: true,
            message: '请输入密码',
          },
          {
            min: 6,
            max: 12,
            message: '请输入6-12位密码',
          },
        ],
      },
    };
  },
  methods: {
    login() {
      console.log('button');
      this.$refs.form.validate((valid) => {
        if (valid) {
          alert('验证成功');
        } else {
          alert('验证失败');
          return false;
        }
      });
    },
  },
};
</script>

<style>
.form {
  width: 30%;
  margin: 150px auto;
}
</style>
